package com.lagou.sqlSession;

import com.lagou.config.XMLConfigBuild;
import com.lagou.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/***
 * （3）解析配置文件，dom4j
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream in) throws Exception {
        //第一：使用dom4j解析配置文件，将解析出来的内容封装到configuration中
        XMLConfigBuild xmlConfigBuild = new XMLConfigBuild();
        Configuration configuration = xmlConfigBuild.parseConfig(in);


        //第二：创建SqlSessionFactory对象:工厂类，生产sqlSession：会话对象
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return defaultSqlSessionFactory;

    }
}
